﻿using System;
using System.Reflection;

public class Person
{
    private string name;
    private int age;

    // 无参构造方法
    public Person()
    {
        this.name = "Default Name";
        this.age = 0;
    }

    // 有参构造方法
    public Person(string name, int age)
    {
        this.name = name;
        this.age = age;
    }

    public void Display()
    {
        Console.WriteLine($"Name: {name}, Age: {age}");
    }
}

class Program
{
    static void Main()
    {
        // 获取 Person 类型
        Type personType = typeof(Person);

        // 1. 调用无参构造方法
        object obj1 = Activator.CreateInstance(personType);
        MethodInfo displayMethod = personType.GetMethod("Display", BindingFlags.Public | BindingFlags.Instance);
        displayMethod.Invoke(obj1, null);

        // 2. 调用有参构造方法
        object obj2 = Activator.CreateInstance(personType, "Alice", 25);
        displayMethod.Invoke(obj2, null);
    }
}
